#Author: 0x9DEFA478

[CmdletBinding(PositionalBinding=$false)]
Param(
  [Parameter(Position=0)]
  $OutFileName,
  $DirTag,
  $FileTag,
  [Parameter(ValueFromRemainingArguments=$true)]
  [string[]]$TargetDirList
)

if($OutFileName -eq $null){
  Write-Host -ForegroundColor:Red "No param: OutFileName"
  exit 1
}

if($TargetDirList.length -lt 1){
  Write-Host -ForegroundColor:Red "TargetDirList too few"
  exit 1
}


Set-Content $OutFileName ""
Add-Content $OutFileName ""
Add-Content $OutFileName ""
Add-Content $OutFileName ""

foreach($TargetDir in $TargetDirList){
  if($DirTag -ne $null){
    $r_path=$TargetDir -replace "\\","/"
    Add-Content $OutFileName "${DirTag}${r_path}"
  }
  Get-ChildItem -Path $TargetDir -Recurse | ForEach-Object {
    $r_path=Resolve-Path $_.FullName -Relative
    $r_path=$r_path -replace "\\","/"
    if($_.PSIsContainer){
      if($DirTag -ne $null){
        Add-Content $OutFileName "${DirTag}${r_path}"
      }
    }else{
      if($FileTag -ne $null){
        Add-Content $OutFileName "${FileTag}${r_path}"
      }
    }
  }
}

Add-Content $OutFileName ""
Add-Content $OutFileName ""
Add-Content $OutFileName ""

